{template 'common/header-gw'}
<ol class="breadcrumb">
	<li><a href="./?refresh"><i class="fa fa-home"></i></a></li>
	<li><a href="{url 'system/welcome'}">系统</a></li>
	<li class="active">字段管理</li>
</ol>
<ul class="nav nav-tabs">
	<li {if $do == 'display'}class="active"{/if}><a href="{url 'user/fields'}">字段管理</a></li>
	<li {if empty($id) && $do == 'post'}class="active"{/if}><a href="{url 'user/fields/post'}">添加字段</a></li>
	{if !empty($id) && $do == 'post'}<li class="active"><a href="{php echo url('user/fields/post', array('id' => $id));}">编辑字段</a></li>{/if}
</ul>
{if $do == 'display'}
<form action="" method="post">
<div class="table-responsive clearfix">
	<h5 class="page-header">字段管理</h5>
	<div class="panel panel-default">
	<div class="panel-body table-responsive">
	<table class="table table-hover">
		<thead class="navbar-inner">
			<tr>
				<th>排序</th>
				<th>字段名</th>
				<th>标题</th>
				<th>是否启用</th>
				<th>注册页显示</th>
				<th>是否必填</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			{loop $fields $field}
			<tr>
				<td>
					<input type="text" class="form-control" style="width:50%;" name="displayorder[{$field['id']}]" value="{$field['displayorder']}">
				</td>
				<td style="vertical-align:middle;"><div>{$field['field']}</div></td>
				<td style="vertical-align:middle;">{$field['title']}</td>
				<td style="vertical-align:middle;"><input type="checkbox" name="available[{$field['id']}]" value="1" {if $field['available']}checked{/if}/></td>
				<td style="vertical-align:middle;"><input type="checkbox" name="showinregister[{$field['id']}]" value="1" {if $field['showinregister']}checked{/if}/></td>
				<td style="vertical-align:middle;"><input type="checkbox" name="required[{$field['id']}]" value="1" {if $field['required']}checked{/if}/></td>
				<td style="vertical-align:middle;"><a href="{php echo url('user/fields/post', array('id' => $field['id']))}" title="编辑">编辑</a></td>
			</tr>
			{/loop}
		</tbody>
	</table>
	</div>
	</div>
	<div>
		<button type="submit" class="btn btn-primary col-lg-1" name="submit" value="提交">提交</button>
		<input type="hidden" name="token" value="{$_W['token']}" />
	</div>
</div>

</form>
{elseif $do == 'post'}
<div class="clearfix">
	<h5 class="page-header">编辑字段</h5>
	<form class="form-horizontal form" action="" method="post">
		<input type="hidden" name="id" value="{$item['id']}">
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">字段</label>
			<div class="col-sm-10 col-xs-12">
				<input type="text" class="form-control" placeholder="请使用字母或数字或下划线组合字段名" name="field"  value="{$item['field']}" {if !empty($item['field'])}readonly{/if}>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">字段长度</label>
			<div class="col-sm-10 col-xs-12">
				<select class="form-control" name="length" >
					<option value="64" {if $item['field_length'] == 64}selected{/if}>64</option>
					<option value="128" {if $item['field_length'] == 128}selected{/if}>128</option>
					<option value="255" {if $item['field_length'] == 255}selected{/if}>255</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">排序</label>
			<div class="col-sm-10 col-xs-12">
				<input type="text" class="form-control" placeholder="" name="displayorder" value="{$item['displayorder']}">
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">名称</label>
			<div class="col-sm-10 col-xs-12">
					<input type="text" class="form-control" placeholder="" name="title" value="{$item['title']}">
					<input type="hidden" name="name_old" value="{$item['Field']}">
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">描述</label>
			<div class="col-sm-10 col-xs-12">
					<textarea style="height:100px;" class="form-control" name="description" cols="50">{$item['description']}</textarea>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">是否启用</label>
			<div class="col-sm-10 col-xs-12">
					<label for="radio_1" class="radio-inline"><input type="radio" name="available" id="radio_1" value="1" {if empty($item) || $item['available'] == 1} checked{/if} /> 是</label>
					<label for="radio_0" class="radio-inline"><input type="radio" name="available" id="radio_0" value="0" {if !empty($item) && $item['available'] == 0} checked{/if} /> 否</label>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">是否必填</label>
			<div class="col-sm-10 col-xs-12">
					<label for="radio_6" class="radio-inline"><input type="radio" name="required" id="radio_6" value="1" {if empty($item) || $item['required'] == 1} checked{/if} /> 是</label>
					<label for="radio_7" class="radio-inline"><input type="radio" name="required" id="radio_7" value="0" {if !empty($item) && $item['required'] == 0} checked{/if} /> 否</label>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">提交后不可修改</label>
			<div class="col-sm-10 col-xs-12">
					<label for="radio_3" class="radio-inline"><input type="radio" name="unchangeable" id="radio_3" value="1" {if empty($item) || $item['unchangeable'] == 1} checked{/if} /> 是</label>
					<label for="radio_2" class="radio-inline"><input type="radio" name="unchangeable" id="radio_2" value="0" {if !empty($item) && $item['unchangeable'] == 0} checked{/if} /> 否</label>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">在注册页面显示</label>
			<div class="col-sm-10 col-xs-12">
					<label for="radio_4" class="radio-inline"><input type="radio" name="showinregister" id="radio_4" value="1" {if empty($item) || $item['showinregister'] == 1} checked{/if} /> 是</label>
					<label for="radio_5" class="radio-inline"><input type="radio" name="showinregister" id="radio_5" value="0" {if !empty($item) && $item['showinregister'] == 0} checked{/if} /> 否</label>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label"></label>
			<div class="col-sm-10 col-xs-12">
					<button type="submit" class="btn btn-primary" name="submit" value="提交">提交</button>
					<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
	</form>
</div>
<script>
	$('input[name="field"]').blur(function() {
		field_value = $(this).val();
		reg = /^[A-Za-z0-9_]*$/;
		if (!reg.test(field_value)) {
			$(this).val('');
		}
	})
</script>
{/if}
{template 'common/footer-gw'}